package cn.itsource.org.controller;

import cn.itsource.basic.domain.AjaxResult;
import cn.itsource.basic.domain.DeparmentQuery;
import cn.itsource.basic.util.PageList;
import cn.itsource.org.domain.Department;
import cn.itsource.org.service.IDepartmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jdk.nashorn.api.scripting.AbstractJSObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("dept")
@Api(value = "部门管理",description = "部门管理")
public class DepartmentController {
    @Autowired
    private IDepartmentService departmentService;

    @ApiOperation(value = "高级分页查询",notes = "高级分页查询")
    @PostMapping("findPage")
    public AjaxResult page(@RequestBody DeparmentQuery query){
        PageList<Department> page = departmentService.page(query);
        return AjaxResult.setResult(page);
    }
    @ApiOperation(value = "查询所有",notes = "查询所有")
    @PostMapping("findAll")
    public AjaxResult findAll(){
        List<Department> all = departmentService.findAll();
        return AjaxResult.setResult(all);
    }

    @ApiOperation(value = "查询单个",notes = "单个查询")
    @GetMapping("findOne/{id}")
    public AjaxResult findOne(@PathVariable("id") Long id){
        Department one = departmentService.findOne(id);
        return AjaxResult.setResult(one);
    }
    @ApiOperation(value = "新增",notes = "新增")
    @PostMapping("insert")
    public AjaxResult insert(@RequestBody Department department){
        departmentService.insert(department);
        return AjaxResult.me();
    }
    @ApiOperation(value = "修改",notes = "修改")
    @GetMapping("update/{id}")
    public AjaxResult update(@RequestBody Department department){
        departmentService.update(department);
        return AjaxResult.me();
    }
    @ApiOperation(value = "删除",notes = "删除")
    @GetMapping("delete/{id}")
    public AjaxResult delete(@PathVariable("id") Long id){
        departmentService.delete(id);
        return AjaxResult.me();
    }
    @ApiOperation(value = "批量删除",notes = "批量删除")
    @PostMapping("deleteBase")
    public AjaxResult deleteBase(@RequestBody List<Long> ids){
        departmentService.deleteBatch(ids);
        return AjaxResult.me();
    }

}
